package com.me.mygdxgame.Components;
import java.util.ArrayList;

import com.me.mygdxgame.Component;
import com.me.mygdxgame.RoundHandler;
import com.me.mygdxgame.TabletWars;
import com.me.mygdxgame.UNITTYPE;
import com.me.mygdxgame.GameObjects.Unit;

public class Attack extends Component {
	int dmg;
	private final static float boniMultiplicator = 1.5f;
	private final static float fortifyMultiplicator = 0.5f;
	
	public Attack(int dmg){
		this.dmg = dmg;
	}
	
	public void attack(ArrayList<Unit> targets) {
		Unit parentUnit = (Unit)this.parentObject;
		UNITTYPE parentUnittype = parentUnit.getUnittype();
		
		for(Unit target:targets) {
			if(target != null){
				Health currentTargetsHealth = (Health)target.getComponent("Health");
				//Health currentTargetsHealth = new Health(100);
				currentTargetsHealth.reduceHealth(this.calculateDmg(parentUnittype, target));
				System.out.print(currentTargetsHealth.curHealth);
			}
		}
	}	
	
	int calculateDmg(UNITTYPE attackingUnitsUnittype, Unit targetUnit){
		UNITTYPE targetsUnittype = targetUnit.getUnittype();
		Fortify targetsFortify = (Fortify)targetUnit.getComponent("Fortify");
		boolean targetsFortifyState = targetsFortify.getFority();
		if(targetsFortifyState){
			if(attackingUnitsUnittype == UNITTYPE.FLAMETHROWER){
				if(targetsUnittype == UNITTYPE.SNIPER){
					return (int)(this.dmg * boniMultiplicator * fortifyMultiplicator);
				}
			}
			else if(attackingUnitsUnittype == UNITTYPE.SHOTGUN){
				if(targetsUnittype == UNITTYPE.FLAMETHROWER){
					return (int)(this.dmg * boniMultiplicator * fortifyMultiplicator);
				}
			}
			else if(attackingUnitsUnittype == UNITTYPE.SNIPER){
				if(targetsUnittype == UNITTYPE.SOLDIER){
					return (int)(this.dmg * boniMultiplicator * fortifyMultiplicator);
				}
			}
			else if(attackingUnitsUnittype == UNITTYPE.SOLDIER){
				if(targetsUnittype == UNITTYPE.SHOTGUN){
					return (int)(this.dmg * boniMultiplicator * fortifyMultiplicator);
				}
			}
			return (int)(this.dmg * fortifyMultiplicator);
		}
		return this.dmg;
	}
}
